package com.fms.Logger;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

import junit.framework.TestCase;

import com.fms.data.logger.Logger;

public class LoggerTest extends TestCase
{
	public void testLogger()
	{
		PrintStream p = System.out;
		
		PrintStreamCapture test = null;
		try
		{
			test = new PrintStreamCapture("");
		} catch (FileNotFoundException e)
		{
			fail(e.getMessage());
		}
		System.setOut(test);
		Logger l = new Logger();		
		l.log("Hello World!");
		
		assertTrue("Incorrect text printed: " +test.result, 
				test.result.equals("com.fms.Logger.LoggerTest.testLogger() - Hello World!"));
		
		
		
		System.setOut(p);
		
	}
	
	public class PrintStreamCapture extends PrintStream
	{
		public String result;
		
		public PrintStreamCapture(String fileName) throws FileNotFoundException
		{
			super(new FileOutputStream("test.out"));
			result = "";
			// TODO Auto-generated constructor stub
		}
		
		public void println(String value)
		{
			result += value;
		}
		
	}

}
